<?php

class Customer extends \Eloquent {
	protected $fillable = [];


    public function getArea(){
        return $this->hasMany('Area','city_id','city');
    }
    public function provincename(){
        return $this->hasOne('Area', 'id','province');
    }
    public function cityname(){
        return $this->hasOne('Area', 'id', 'city');
    }
    public function areaname(){
        return $this->hasOne('Area', 'id', 'area');
    }
    public function inviteid(){
        return $this->hasOne('Customer','id','invite_id');
    }

    /**
     * @param $customer_id 增加积分的用户id
     * @param $item 增加积分的操作
     * @param $add 1：加 0：减
     * @param $action_id   相关操作id
     * @param null $user_id 被邀请人id
     */
    public static function add_points($customer_id,$item,$add,$action_id,$user_id = null){

        $customer = Customer::find($customer_id);

        $point = Pointconfig::get_points($item,$customer->city,$customer->type);//查询该操作所获得积分
        if($point > 0){//当积分为0无操作
            $customer->all_points = $customer->all_points+$point;
            $customer->save();
            Pointrecord::new_record($point,$item,$add,$action_id,$customer_id,$user_id);
        }
    }
}